package com.YCH.article.controller.v1;

import com.YCH.apis.article.apis.ArticleCategoryControllerApi;
import com.YCH.article.service.AppLoadUserArticleCategories;
import com.YCH.model.article.dtos.AppUserArticleCategoryDto;
import com.YCH.model.article.pojos.TbArticleCategory;
import com.YCH.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleCategoryController implements ArticleCategoryControllerApi {
    @Autowired
    private AppLoadUserArticleCategories appLoadUserArticleCategories;
    @Override
    @PostMapping("/load_user_article_category")
    public ResponseResult loadUserArticleCategory(@RequestBody AppUserArticleCategoryDto dto) {
        return appLoadUserArticleCategories.getUserArticleCategory(dto);
    }

    @Override
    @PostMapping("/load_category")
    public ResponseResult loadCategory(@RequestBody AppUserArticleCategoryDto dto) {
        return appLoadUserArticleCategories.getCategory(dto);
    }

    @Override
    @PostMapping("/add_category")
    public ResponseResult addUserArticleCategory(@RequestBody TbArticleCategory tbArticleCategory) {
        return appLoadUserArticleCategories.addUserArticleCategory(tbArticleCategory.getName(),tbArticleCategory.getParentId());
    }

    @Override
    @RequestMapping(value = "/delete_category")
    public ResponseResult deleteArticleCategory(@RequestBody TbArticleCategory tbArticleCategory) {
        return appLoadUserArticleCategories.deleteUserArticleCategory(tbArticleCategory.getId());
    }

    @Override
    @RequestMapping(value = "/update_category")
    public ResponseResult updateArticleCategory(@RequestBody TbArticleCategory tbArticleCategory) {
        return appLoadUserArticleCategories.updateUserArticleCategory(tbArticleCategory.getId(),tbArticleCategory.getName());
    }
}
